package com.yun.algorithm.dynamicprogramming.leetcode;

public class HouseRobberLeetcode198 {
    public int rob(int[] house){
        int len = house.length;
        if(len ==1){
            return house[0];
        }
        int[] dp=new int[len];
        dp[0]=house[0];
        dp[1]=Integer.max(house[0],house[1]);
        for (int i = 2; i < len; i++) {
            dp[i]=Integer.max(dp[i-2]+house[i],dp[i-1]);
        }
        return dp[len -1];
    }

    public static void main(String[] args) {
        int[] house=new int[]{2,7,9,3,1};
        new HouseRobberLeetcode198().rob(house);
    }
}
